/*
 * JerboArticlesManage.java
 *
 * Created on March 21, 2008, 12:50 PM
 */

package jerbo;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DecimalFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.JComponent;
import javax.swing.KeyStroke;
import org.jdesktop.application.Action;
import org.jdesktop.application.Application;

/**
 *
 * @author  Luigi Paioro
 */
public class JerboArticlesManage extends javax.swing.JDialog {
    
    public static byte TYPE_ADD = 0;
    public static byte TYPE_MODIFY = 1;
    
    public byte mode = TYPE_ADD;
    
    java.util.ResourceBundle appBundle = java.util.ResourceBundle.getBundle("jerbo/resources/JerboApp"); // NOI18N
    
    /** Creates new form JerboArticlesManage
     * @param parent
     */
    public JerboArticlesManage(java.awt.Frame parent) {
        super(parent);
        initComponents();
        KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
        javax.swing.Action escapeAction = new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    dispose();
                }
            };
        getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE");
        getRootPane().getActionMap().put("ESCAPE", escapeAction);
    }
    
    public void setMode(byte mode) {
        this.mode = mode;
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("jerbo/resources/JerboArticlesManage"); // NOI18N
        operationButton.setText((this.mode == JerboArticlesManage.TYPE_ADD ? bundle.getString("operationButton.text.add") : bundle.getString("operationButton.text.modify")));
        if (this.mode == TYPE_MODIFY)
//            codeText.setEditable(false);
            descriptionText.setEditable(false);
        else {
//            codeText.setEditable(true);
            descriptionText.setEditable(true);
            this.cleanForm();
        }
    }
    
    public byte getMode() {
        return this.mode;
    }
    
    /**
     * 
     * @param description
     */
//    public void loadArticle(String code) {
    public void loadArticle(String description) {
        
//        if (code == null || code.equals(""))
        if (description == null || description.equals(""))
            this.cleanForm();
        else
        
            try {
                Connection conn = Application.getInstance(jerbo.JerboApp.class).getConnection();
                Statement stat = conn.createStatement();
//                ResultSet result = stat.executeQuery("select * from articles where code='" + code + "'");
                ResultSet result = stat.executeQuery("select * from articles where description=\"" + description + "\"");
                if (result.next()) {
                    codeText.setText(result.getString("code"));
                    descriptionText.setText(result.getString("description"));
                    supplierText.setText(result.getString("supplier"));
                    categoryText.setText(result.getString("category"));
                    
                    java.text.DecimalFormatSymbols symbols = new java.text.DecimalFormatSymbols();
                    symbols.setDecimalSeparator('.');
                    DecimalFormat df = new java.text.DecimalFormat(appBundle.getString("Application.currency.format"), symbols);
                    priceText.setText(df.format(result.getFloat("price")));
                    priceSupplierText.setText(df.format(result.getFloat("supplier_price")));
                    vatText.setText(result.getString("vat"));
                    quantityText.setText(result.getString("quantity"));
                    unitText.setText(result.getString("unit"));
                    noteText.setText(result.getString("note"));
                }
                if (result != null) result.close();
                if (stat != null) stat.close();
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(JerboArticles.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(JerboArticles.class.getName()).log(Level.SEVERE, null, ex);
            }        
    }
    
    public void cleanForm() {
        codeText.setText("");
        descriptionText.setText("");
        supplierText.setText("");
        categoryText.setText("");
        priceText.setText("");
        priceSupplierText.setText("");
        vatText.setText("20");
        quantityText.setText("1");
        unitText.setText("");
        noteText.setText("");
    }
        
    @Action 
    public void close() {
        dispose();
    }
    
    @Action
    public void updateArticle() {
        
        //if (!codeText.getText().trim().equals("")) {
        if (!descriptionText.getText().trim().equals("")) {
            
            this.toUpperCase();
            
            try {
                Connection conn = Application.getInstance(jerbo.JerboApp.class).getConnection();
                Statement stat = conn.createStatement();
                String sql = null;
                if (this.mode == TYPE_MODIFY) {
                    sql = "update articles set ";
                    sql += "code = '" + codeText.getText().replaceAll("'", "''") + "',";
                    sql += "supplier = '" + supplierText.getText().replaceAll("'", "''") + "',";
                    sql += "category = '" + categoryText.getText().replaceAll("'", "''") + "',";
                    sql += "price = " + priceText.getText() + ",";
                    sql += "vat = " + vatText.getText().substring(0, 2) + ",";
                    sql += "quantity = " + quantityText.getText() + ",";
                    sql += "unit = '" + unitText.getText().replaceAll("'", "''") + "',";
                    sql += "note = '" + noteText.getText().replaceAll("'", "''") + "',";
                    sql += "supplier_price = " + priceSupplierText.getText();
                    sql += " where description = '" + descriptionText.getText().replaceAll("'", "''") + "'";
                } else {
                    sql = "insert or replace into articles values (";
                    sql += "'" + codeText.getText().replaceAll("'", "''") + "',";
                    sql += "'" + descriptionText.getText().replaceAll("'", "''") + "',";
                    sql += "'" + supplierText.getText().replaceAll("'", "''") + "',";
                    sql += "'" + categoryText.getText().replaceAll("'", "''") + "',";
                    sql += priceText.getText() + ",";
                    sql += vatText.getText().substring(0, 2) + ",";
                    sql += quantityText.getText() + ",";
                    sql += "'" + unitText.getText().replaceAll("'", "''") + "',";
                    sql += "'" + noteText.getText().replaceAll("'", "''") + "',";
                    sql += priceSupplierText.getText() + ")";
                }
                stat.executeUpdate(sql);
                if (stat != null) stat.close();
                this.close();
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(JerboArticles.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(JerboArticles.class.getName()).log(Level.SEVERE, null, ex);
            }        
            
        }
    }
    
    public void toUpperCase() {
        codeText.setText(codeText.getText().toUpperCase());
        descriptionText.setText(descriptionText.getText().toUpperCase());
        supplierText.setText(supplierText.getText().toUpperCase());
        categoryText.setText(categoryText.getText().toUpperCase());
        unitText.setText(unitText.getText().toUpperCase());
        noteText.setText(noteText.getText().toUpperCase());
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        codeText = new javax.swing.JTextField();
        codeLabel = new javax.swing.JLabel();
        descriptionLabel = new javax.swing.JLabel();
        descriptionText = new javax.swing.JTextField();
        priceLabel = new javax.swing.JLabel();
        java.util.ResourceBundle appBundle = java.util.ResourceBundle.getBundle("jerbo/resources/JerboApp"); // NOI18N
        java.text.DecimalFormatSymbols symbols = new java.text.DecimalFormatSymbols();
        symbols.setDecimalSeparator('.');
        priceText = new javax.swing.JFormattedTextField(new java.text.DecimalFormat(appBundle.getString("Application.currency.format"), symbols));
        supplierLabel = new javax.swing.JLabel();
        supplierText = new javax.swing.JTextField();
        findSupplierButton = new javax.swing.JButton();
        categoryLabel = new javax.swing.JLabel();
        categoryText = new javax.swing.JTextField();
        findCategoryButton = new javax.swing.JButton();
        quantityLabel = new javax.swing.JLabel();
        quantityText = new javax.swing.JTextField();
        unitLabel = new javax.swing.JLabel();
        unitText = new javax.swing.JTextField();
        closeButton = new javax.swing.JButton();
        operationButton = new javax.swing.JButton();
        noteScrollPane = new javax.swing.JScrollPane();
        noteText = new javax.swing.JTextArea();
        noteLabel = new javax.swing.JLabel();
        vatLabel = new javax.swing.JLabel();
        try {
            javax.swing.text.MaskFormatter mf = new javax.swing.text.MaskFormatter("##%");
            mf.setPlaceholderCharacter('0');
            vatText = new javax.swing.JFormattedTextField(mf);
        } catch (java.text.ParseException pEx) {
            pEx.printStackTrace();
        }
        symbols.setDecimalSeparator('.');
        priceSupplierText = new javax.swing.JFormattedTextField(new java.text.DecimalFormat(appBundle.getString("Application.currency.format"), symbols));
        priceSupplierLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("jerbo/resources/JerboArticlesManage"); // NOI18N
        setTitle(bundle.getString("title.text")); // NOI18N
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setModal(true);
        setName("Form"); // NOI18N
        setResizable(false);

        codeText.setName("codeText"); // NOI18N
        codeText.setNextFocusableComponent(descriptionText);
        codeText.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                codeTextFocusLost(evt);
            }
        });
        codeText.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                codeTextKeyPressed(evt);
            }
        });

        codeLabel.setText(bundle.getString("codeLabel.text")); // NOI18N
        codeLabel.setName("codeLabel"); // NOI18N

        descriptionLabel.setText(bundle.getString("descriptionLabel.text")); // NOI18N
        descriptionLabel.setName("descriptionLabel"); // NOI18N

        descriptionText.setName("descriptionText"); // NOI18N
        descriptionText.setNextFocusableComponent(supplierText);
        descriptionText.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                descriptionTextFocusLost(evt);
            }
        });

        priceLabel.setText(bundle.getString("priceLabel.text")); // NOI18N
        priceLabel.setName("priceLabel"); // NOI18N

        priceText.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        priceText.setName("priceText"); // NOI18N
        priceText.setNextFocusableComponent(vatText);

        supplierLabel.setText(bundle.getString("supplierLabel.text")); // NOI18N
        supplierLabel.setName("supplierLabel"); // NOI18N

        supplierText.setName("supplierText"); // NOI18N
        supplierText.setNextFocusableComponent(categoryText);
        supplierText.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                supplierTextFocusLost(evt);
            }
        });

        findSupplierButton.setText(bundle.getString("findSupplierButton.text")); // NOI18N
        findSupplierButton.setEnabled(false);
        findSupplierButton.setName("findSupplierButton"); // NOI18N
        findSupplierButton.setNextFocusableComponent(findCategoryButton);

        categoryLabel.setText(bundle.getString("categoryLabel.text")); // NOI18N
        categoryLabel.setName("categoryLabel"); // NOI18N

        categoryText.setName("categoryText"); // NOI18N
        categoryText.setNextFocusableComponent(priceText);
        categoryText.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                categoryTextFocusLost(evt);
            }
        });

        findCategoryButton.setText(bundle.getString("findCategoryButton.text")); // NOI18N
        findCategoryButton.setEnabled(false);
        findCategoryButton.setName("findCategoryButton"); // NOI18N
        findCategoryButton.setNextFocusableComponent(closeButton);

        quantityLabel.setText(bundle.getString("quantityLabel.text")); // NOI18N
        quantityLabel.setName("quantityLabel"); // NOI18N

        quantityText.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        quantityText.setName("quantityText"); // NOI18N
        quantityText.setNextFocusableComponent(unitText);

        unitLabel.setText(bundle.getString("unitLabel.text")); // NOI18N
        unitLabel.setName("unitLabel"); // NOI18N

        unitText.setName("unitText"); // NOI18N
        unitText.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                unitTextFocusLost(evt);
            }
        });

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(jerbo.JerboApp.class).getContext().getActionMap(JerboArticlesManage.class, this);
        closeButton.setAction(actionMap.get("close")); // NOI18N
        closeButton.setText(bundle.getString("closeButton.text")); // NOI18N
        closeButton.setName("closeButton"); // NOI18N
        closeButton.setNextFocusableComponent(codeText);

        operationButton.setAction(actionMap.get("updateArticle")); // NOI18N
        operationButton.setText((this.mode == this.TYPE_ADD ? bundle.getString("operationButton.text.add") : bundle.getString("operationButton.text.modify")));
        operationButton.setName("operationButton"); // NOI18N
        operationButton.setNextFocusableComponent(findSupplierButton);

        noteScrollPane.setName("noteScrollPane"); // NOI18N

        noteText.setColumns(20);
        noteText.setRows(5);
        noteText.setTabSize(4);
        noteText.setName("noteText"); // NOI18N
        noteText.setNextFocusableComponent(operationButton);
        noteText.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                noteTextFocusLost(evt);
            }
        });
        noteScrollPane.setViewportView(noteText);

        noteLabel.setText(bundle.getString("noteLabel.text")); // NOI18N
        noteLabel.setName("noteLabel"); // NOI18N

        vatLabel.setText(bundle.getString("vatLabel.text")); // NOI18N
        vatLabel.setName("vatLabel"); // NOI18N

        vatText.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        vatText.setName("vatText"); // NOI18N
        vatText.setNextFocusableComponent(quantityText);

        priceSupplierText.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        priceSupplierText.setName("priceSupplierText"); // NOI18N
        priceSupplierText.setNextFocusableComponent(vatText);

        priceSupplierLabel.setText(bundle.getString("priceSupplierLabel.text")); // NOI18N
        priceSupplierLabel.setName("priceSupplierLabel"); // NOI18N

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(layout.createSequentialGroup()
                            .add(noteScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 422, Short.MAX_VALUE)
                            .addContainerGap())
                        .add(layout.createSequentialGroup()
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(descriptionLabel)
                                .add(supplierLabel)
                                .add(categoryLabel)
                                .add(noteLabel)
                                .add(layout.createSequentialGroup()
                                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                        .add(org.jdesktop.layout.GroupLayout.LEADING, codeText)
                                        .add(org.jdesktop.layout.GroupLayout.LEADING, descriptionText)
                                        .add(org.jdesktop.layout.GroupLayout.LEADING, supplierText)
                                        .add(org.jdesktop.layout.GroupLayout.LEADING, categoryText)
                                        .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                                .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                                                    .add(priceLabel)
                                                    .add(33, 33, 33))
                                                .add(org.jdesktop.layout.GroupLayout.LEADING, quantityText)
                                                .add(org.jdesktop.layout.GroupLayout.LEADING, quantityLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .add(org.jdesktop.layout.GroupLayout.LEADING, priceText))
                                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                                .add(unitLabel)
                                                .add(unitText)
                                                .add(priceSupplierText, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE)
                                                .add(priceSupplierLabel))
                                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                                .add(vatLabel)
                                                .add(vatText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 90, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(org.jdesktop.layout.GroupLayout.TRAILING, findCategoryButton)
                                        .add(findSupplierButton))))
                            .addContainerGap())
                        .add(codeLabel))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(operationButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(closeButton)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(codeLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(codeText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(descriptionLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(descriptionText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(supplierLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(supplierText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(findSupplierButton))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(categoryLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(categoryText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(findCategoryButton))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(priceLabel)
                    .add(vatLabel)
                    .add(priceSupplierLabel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(priceText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(priceSupplierText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(vatText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(quantityLabel)
                    .add(unitLabel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(quantityText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(unitText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(noteLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(noteScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(closeButton)
                    .add(operationButton))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void codeTextKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_codeTextKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER)
            this.loadArticle(codeText.getText());
    }//GEN-LAST:event_codeTextKeyPressed

    private void codeTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_codeTextFocusLost
        codeText.setText(codeText.getText().toUpperCase());
    }//GEN-LAST:event_codeTextFocusLost

    private void descriptionTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_descriptionTextFocusLost
        descriptionText.setText(descriptionText.getText().toUpperCase());
    }//GEN-LAST:event_descriptionTextFocusLost

    private void supplierTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_supplierTextFocusLost
        supplierText.setText(supplierText.getText().toUpperCase());
    }//GEN-LAST:event_supplierTextFocusLost

    private void categoryTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_categoryTextFocusLost
        categoryText.setText(categoryText.getText().toUpperCase());
    }//GEN-LAST:event_categoryTextFocusLost

    private void unitTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_unitTextFocusLost
        unitText.setText(unitText.getText().toUpperCase());
    }//GEN-LAST:event_unitTextFocusLost

    private void noteTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_noteTextFocusLost
        noteText.setText(noteText.getText().toUpperCase());
    }//GEN-LAST:event_noteTextFocusLost
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel categoryLabel;
    private javax.swing.JTextField categoryText;
    private javax.swing.JButton closeButton;
    private javax.swing.JLabel codeLabel;
    private javax.swing.JTextField codeText;
    private javax.swing.JLabel descriptionLabel;
    private javax.swing.JTextField descriptionText;
    private javax.swing.JButton findCategoryButton;
    private javax.swing.JButton findSupplierButton;
    private javax.swing.JLabel noteLabel;
    private javax.swing.JScrollPane noteScrollPane;
    private javax.swing.JTextArea noteText;
    private javax.swing.JButton operationButton;
    private javax.swing.JLabel priceLabel;
    private javax.swing.JLabel priceSupplierLabel;
    private javax.swing.JFormattedTextField priceSupplierText;
    private javax.swing.JFormattedTextField priceText;
    private javax.swing.JLabel quantityLabel;
    private javax.swing.JTextField quantityText;
    private javax.swing.JLabel supplierLabel;
    private javax.swing.JTextField supplierText;
    private javax.swing.JLabel unitLabel;
    private javax.swing.JTextField unitText;
    private javax.swing.JLabel vatLabel;
    private javax.swing.JFormattedTextField vatText;
    // End of variables declaration//GEN-END:variables
    
}
